home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / deditl.cpp < prev    next >
C/C++ Source or Header  |  1994-10-10  |  4KB  |  136 lines

  1. #include "deditl.h"
  2. #include "cursor.h"
  3.  
  4. //////////////////////
  5. void DiacomEditLine::exe(int act)
  6.     {
  7.     Cursor curs;
  8.     mouseHideCursor();
  9.     hilite();
  10.  
  11.     e.what = act ? KEYEVENT : NOEVENT;
  12.     global_i[0] = action_type;
  13.     switch(act)
  14.     {                                         // up, dn and so on may be added
  15.     case AC_CANCEL:
  16.         e.key = (isRet(RET_REMOVE))
  17.         ? EVENT_ALT_F3 : EVENT_ESC;
  18.         break;
  19.     case AC_OK:
  20.         e.key = EVENT_F2;
  21.         break;
  22.     }
  23.  
  24.     char* temp_str = string ? strdup(string) : strdup("");  // reserv copy
  25.  
  26.     string = (char*)realloc(string, 256);   // maximum, before exiting function
  27.     memset(string, '\0', 256);              // it will be reallocated
  28.  
  29.     strcpy(string, temp_str);
  30.     int cur_pos = 0;                    // current pos in string
  31.     int vis_pos = 0;                    // output begins from this position
  32.     settextjustify(LEFT_TEXT, BOTTOM_TEXT);
  33.  
  34.     curs.set_cursor(screenXL(xy.X) + area[border_type].origin.X,
  35.             screenYT(xy.Y) + pScreenSet->standart_height
  36.             + area[border_type].origin.Y);
  37.     curs.show_cursor();
  38.  
  39.     while(1)
  40.     {
  41.     if(!act)     // if act == 0 - we wait the event, else (f.e. CANCEL
  42.              // button pressed) - we process act, not event
  43.         {
  44.         mouseShowCursor();
  45.         get_event();
  46.         mouseHideCursor();
  47.         }
  48.  
  49.     int x = getx();    int y = gety();
  50.  
  51.     curs.set_cursor(screenXL(xy.X + cur_pos - vis_pos)
  52.         + area[border_type].origin.X,
  53.            screenYT(xy.Y) + pScreenSet->standart_height
  54.         + area[border_type].origin.Y);
  55.     curs.hide_cursor();
  56.     ::moveto(x, y);
  57.  
  58.     if(e.mouse1() || e.mouse2())   // mouse pressed
  59.         {
  60.         global_i[0] = 0;
  61.         break;
  62.         }
  63.     else
  64.         {
  65.         if(e.is_control())         // not visible char
  66.                 {
  67.                 switch(e.key)
  68.                     {
  69.                     case EVENT_LEFT: //global_i[0] = AC_LEFT; break;
  70.             case EVENT_RIGHT: //global_i[0] = AC_RIGHT; break;
  71.                     case EVENT_UP: //global_i[0] = AC_UP; break;
  72.                     case EVENT_DN: global_i[0] = 0; break; //AC_DOWN; break;
  73.             }
  74.         switch(e.key)
  75.             {
  76.             case EVENT_F1: return;
  77.             case EVENT_HOME: home(&cur_pos, &vis_pos); break;
  78.             case EVENT_END: end(&cur_pos, &vis_pos); break;
  79.  
  80.             case EVENT_DEL: del(&cur_pos, &vis_pos);  break;
  81.             case EVENT_BKSP: bksp(&cur_pos, &vis_pos); break;
  82.             case EVENT_INS: ins = !ins; break;
  83.             case EVENT_F10:
  84.             case EVENT_ESC: delete string; global_i[0] = 0;
  85.             string = strdup(temp_str); // don't change string
  86.             case EVENT_TAB:
  87.             case EVENT_F6:
  88.             case EVENT_F2:
  89.             case EVENT_ALT_F3:
  90.             case EVENT_ALT_F4:
  91.             case EVENT_ALT_TAB:
  92.                     case EVENT_LEFT:
  93.             case EVENT_RIGHT:
  94.                     case EVENT_UP:
  95.                     case EVENT_DN:
  96.             case EVENT_RETURN:
  97.             string =
  98.                 (char*)realloc(string, strlen(string) + 2);
  99.             delete temp_str;
  100.             unhilite();
  101.             delete global[global_num];
  102.             if(global_num)
  103.                 delete global[0];
  104.             global[global_num] = strdup(string);
  105.             if(global_num)
  106.                 global[0] = strdup(string);
  107.             return;
  108.             }
  109.                 }
  110.         else
  111.         if(e.is_char())   // visible char
  112.             {
  113.             outkey = e.key;
  114.             draw_char(&cur_pos, &vis_pos);
  115.             }
  116.  
  117.         }
  118.     x = getx();       // new coords recalculation
  119.     y = gety();
  120.     curs.set_cursor(screenXL(xy.X + cur_pos - vis_pos)
  121.         + area[border_type].origin.X,
  122.         screenYT(xy.Y) + pScreenSet->standart_height
  123.         + area[border_type].origin.Y);
  124.     curs.show_cursor();
  125.     moveto(x, y);
  126.     }
  127. // if mouse pressed outside - we keep the edited string
  128.     string = (char*)realloc(string, strlen(string) + 2);
  129.     delete temp_str;
  130.     unhilite();
  131.     delete global[global_num]; global[global_num] = strdup(string);
  132.     delete global[0]; global[0] = strdup(string);
  133.     return;
  134.     }
  135. //////////////////////
  136.